﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.货号管理.service;
using DevExpress.XtraGrid.Demos.util;

namespace DXApplicationTangche.UC.货号管理
{
    public partial class XtraUserControl工序显示设计 : DevExpress.XtraEditors.XtraUserControl
    {
        public List<GarmentExceptionDTO> garmentExceptionDTOs = new List<GarmentExceptionDTO>();//异常列表
        public String projectInstanceCode { get; set; }//工序code
        public String barcode { get; set; }//成衣码
        public XtraUserControl工序显示设计()
        {
            InitializeComponent();
        }
        public void refreahData(String projectInstanceCode, String styleNameCn, Boolean isSeller)
        {
            this.barcode = null;
            this.projectInstanceCode = projectInstanceCode;
            this.gridControl款式设计一览.DataSource
                = 款式迭代Service.getProjectCraftByProjectCodeAndStyleNameCn(projectInstanceCode, styleNameCn, isSeller);
            this.gridView款式设计一览.RefreshData();
        }
        public void refreahData(String projectInstanceCode, String barcode, String styleNameCn, Boolean isSeller)
        {
            this.barcode = barcode;
            this.projectInstanceCode = projectInstanceCode;
            this.gridControl款式设计一览.DataSource
                = 款式迭代Service.getProjectCraftByProjectCodeAndStyleNameCn(projectInstanceCode, styleNameCn, isSeller);
            this.gridView款式设计一览.RefreshData();
        }
        public void clearData()
        {
            this.gridControl款式设计一览.DataSource = null;
            this.gridView款式设计一览.RefreshData();
        }

        private void simpleButton提交异常_Click(object sender, EventArgs e)
        {
            new Form成衣异常提交(
                    this.barcode,
                    this.projectInstanceCode,
                    this.garmentExceptionDTOs
                    ).ShowDialog();
        }

        private void gridView款式设计一览_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            if (this.gridView款式设计一览.IsRowSelected(this.gridView款式设计一览.FocusedRowHandle))
            {
                this.garmentExceptionDTOs.Add(
                    new GarmentExceptionDTO(
                        FunctionHelper.GetgridViewValue(this.gridView款式设计一览, this.gridView款式设计一览.FocusedRowHandle, "craftDesignDesc"),
                        FunctionHelper.GetgridViewValue(this.gridView款式设计一览, this.gridView款式设计一览.FocusedRowHandle, "id")
                        ));
            }
            else if (!this.gridView款式设计一览.IsRowSelected(this.gridView款式设计一览.FocusedRowHandle))
            {
                for (int i = this.garmentExceptionDTOs.Count-1; i >= 0 ; i--)
                {
                    if (FunctionHelper.GetgridViewValue(this.gridView款式设计一览, this.gridView款式设计一览.FocusedRowHandle, "id").Trim()
                        .Equals(this.garmentExceptionDTOs[i].craftDesignsId)
                        )
                    {
                        this.garmentExceptionDTOs.Remove(this.garmentExceptionDTOs[i]);
                    }
                }
            }
        }
    }
}
